package com.fyp.tests;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/*
 *  ============================================================================
 *  This file is part of 4YProject.
 *
 *  4YProject is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  4YProject is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with 4YProject; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *  ============================================================================
 */

/**
 *  ============================================================================
 *  The following class TestDBDelete.java provides a simple way to delete a
 *  record from a database.
 *
 *  @version 1.0
 *  @author  Sean Crowley
 *  @date    29 Jan 2008
 *  ============================================================================
 */

public class TestDBDelete {
	public static void main(String[] args) {
	    System.out.println("An example for Deleting a Row from a Database!");
	    Connection con = null;
	    String url = "jdbc:derby:";
	    String driver = "org.apache.derby.jdbc.EmbeddedDriver";
	    String db = "/DerbyDB/AssetDB";
	    try{
	      Class.forName(driver);
	      con = DriverManager.getConnection(url + db);
	      try{
	        Statement st = con.createStatement();
	        String sql = "DELETE FROM Requests WHERE Title = 'hello'";
	        int delete = st.executeUpdate(sql);
	        if(delete == 1){
	          System.out.println("Row is deleted.");
	        }
	        else{
	          System.out.println("Row is not deleted.");
	        }
	      }
	      catch (SQLException s){
	        System.out.println("SQL statement is not executed!");
	      }
	    }
	    catch (Exception e){
	      e.printStackTrace();
	    }
	  }
	}
